package com.edu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Emp implements BeanNameAware, ApplicationContextAware {

    private int empId;

    private String empName;

    private Depart depart;

    private double salary;

    private String beanId;

    public String getBeanId() {
        return beanId;
    }

    public void init(){

    }
    public double getSalary() {
       if(depart.getDepartId() == 1){
           return 6000.00;
       }else if(depart.getDepartId() == 2){
           return 4000.00;
       }else{
           return 0;
       }
    }



    public Depart getDepart() {
        return depart;
    }

    public void setDepart(Depart depart) {
        System.out.println("给员工设置了部门");
        this.depart = depart;
    }

    public int getEmpId() {
        return empId;
    }

    public void setEmpId(int empId) {
        this.empId = empId;
    }

    public String getEmpName() {
        return empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }

    public Emp() {
        System.out.println("执行了员工的构造方法");

    }

    @Override
    public String toString() {
        return "Emp{" +
                "empId=" + empId +
                ", empName='" + empName + '\'' +
                ", depart=" + depart +
                ", salary=" + salary +
                '}';
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("执行了 BeanNameAware 接口的方法，由Spring框架 注入了 当前bean的Id(name)");
        System.out.println(s);
        this.beanId = s;
    }



    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(applicationContext);
    }
}
